import types
from typing import TypeVar

T = TypeVar('T')


def Singleton(Original: T) -> T:
    """
    单例类，通过getSingleton方法暴露实例
    """
    # if not hasattr(Original, '_INSTANCE'):
    Original._INSTANCE = None

    def getSingleton(cls, *args, **kwargs) -> Original:
        if cls._INSTANCE is None:
            cls._INSTANCE = Original(*args, **kwargs)
        return cls._INSTANCE

    Original.getSingleton = types.MethodType(getSingleton, Original)
    return Original
